﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WorkflowWizart.Lib.Utility.Costants;

namespace WorkflowWizart.Lib.Entities
{
    public class ObjectData
    {
        public string Name
        {
            get
            {
                return DisplayName.Trim().Replace(" ", "_");
            }
        }

        public string DisplayName { get; set; }

        private List<ObjectField> _Fields = null;
        public List<ObjectField> Fields
        {
            get
            {
                return _Fields;
            }
        }

        private List<ObjectRow> _Rows;
        public List<ObjectRow> Rows
        {
            get
            {
                return Rows;
            }
        }

        public ObjectRow this[int index]
        {
            get { return Rows[index]; }
            set { Rows[index] = value; }
        }
          
        public ObjectField AddField(ColumnDataTypes dataType, string name, string relationalDataColumnId)
        {
            ObjectField column = new ObjectField();
            column.DataType = dataType;
            column.Name = name;
            column.ParentObject = this;
            return AddField(column);
        }

        public ObjectField AddField(ObjectField column)
        {
            if (_Fields == null)
            {
                _Fields = new List<ObjectField>();
            }
            column.ParentObject = this;
            Fields.Add(column);
            return column;
        }
        public ObjectRow AddRow(List<object> data)
        {
            return AddRow(string.Empty, data);
        }
        public ObjectRow AddRow(string id, List<object> data)
        {
            ObjectRow row = new ObjectRow(); 
            row.RowData = data;
            return AddRow(row);
        }

        public ObjectRow AddRow(ObjectRow row)
        {
            if (_Rows==null)
            {
                _Rows = new List<ObjectRow>();
            }
            row.ParentObject = this;
            Rows.Add(row);
            return row;
        }
    }
}
